import java.util.Arrays;

public class SolutionInterview16_13 {
    public double[] cutSquares(int[] square1, int[] square2) {
        double x1=square1[0]+square1[2]/2.0,y1=square1[1]+square1[2]/2.0;
        double x2=square2[0]+square2[2]/2.0,y2=square2[1]+square2[2]/2.0;
        if (x1==x2 && y1==y2){
            return new double[]{x1,Math.min(square1[1],square2[1]),x1,Math.max(square1[1]+square1[2],square2[1]+square2[2])};
        }
        int minL,lMinY,lMaxY;
        if (square1[0]<square2[0]){
            minL=square1[0];
            lMinY=square1[1];
            lMaxY=square1[1]+square1[2];
        }else{
            minL=square2[0];
            lMinY=square2[1];
            lMaxY=square2[1]+square2[2];
        }
        int minD,dMinX,dMaxX;
        if (square1[1]<square2[1]){
            minD=square1[1];
            dMinX=square1[0];
            dMaxX=square1[0]+square1[2];
        }else{
            minD=square2[1];
            dMinX=square2[0];
            dMaxX=square2[0]+square2[2];
        }
        int maxR,rMinY,rMaxY;
        if (square1[0]+square1[2]>square2[0]+square2[2]){
            maxR=square1[0]+square1[2];
            rMinY=square1[1];
            rMaxY=square1[1]+square1[2];
        }else{
            maxR=square2[0]+square2[2];
            rMinY=square2[1];
            rMaxY=square2[1]+square2[2];
        }
        int maxU,uMinX,uMaxX;
        if (square1[1]+square1[2]>square2[1]+square2[2]){
            maxU=square1[1]+square1[2];
            uMinX=square1[0];
            uMaxX=square1[0]+square1[2];
        }else{
            maxU=square2[1]+square2[2];
            uMinX=square2[0];
            uMaxX=square2[0]+square2[2];
        }
        double[] ans=new double[4];
        double[] d1=check1(x1,y1,x2,y2,minL,lMinY,lMaxY);
        if (d1==null) {
            d1=check2(x1,y1,x2,y2,minD,dMinX,dMaxX);
        }
        ans[0]=d1[0];
        ans[1]=d1[1];
        double[] d2=check1(x1,y1,x2,y2,maxR,rMinY,rMaxY);
        if (d2==null){
            d2=check2(x1,y1,x2,y2,maxU,uMinX,uMaxX);
        }
        ans[2]=d2[0];
        ans[3]=d2[1];
        if (ans[0]>ans[2]){
            double t=ans[0];
            ans[0]=ans[2];
            ans[2]=t;
            t=ans[1];
            ans[1]=ans[3];
            ans[3]=t;
        }
        return ans;
    }

    private double[] check2(double x1, double y1, double x2, double y2, int targetY, int minX, int maxX) {
        if (y1==y2){
            return null;
        }
        double x=(x2-x1)/(y2-y1)*(targetY-y1)+x1;
        if (x>=minX && x<=maxX){
            return new double[]{x,targetY};
        }
        return null;
    }

    private double[] check1(double x1, double y1, double x2, double y2, int targetX, int minY, int maxY) {
        if (x1==x2){
            return null;
        }
        double y=(y2-y1)/(x2-x1)*(targetX-x1)+y1;
        if (y>=minY && y<=maxY){
            return new double[]{targetX,y};
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new SolutionInterview16_13().cutSquares(new int[]{-2, -2, 5}, new int[]{-3, -3, 7})));
    }
}
